<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
    jQuery.noConflict();

    var a=new Array;
    var link=new Array;
    var styleForThumb = '<?php echo $style; ?>' ;
    var setShowThumbs = '<?php echo $setShowThumbs; ?>'
//    var animation = '';
<?php


//global $JSONfolder;

    if (isset($JSONfolder)) {//caso json
        for ($i = 0; $i < count($images); $i++) {
//    echo "a[$i]='" . $imgFolder . "/" . $images[$i]['nameImg'] . "';\n";
            echo "a[$i]='" . $images[$i]['nameImg'] . "';\n";
            if (strrpos($images[$i]['linkImage'], 'http') !== false)
                echo "link[$i]='" . $images[$i]['linkImage'] . "';\n";
            else
                echo "link[$i]='http://" . $images[$i]['linkImage'] . "';\n";
        }
    }
    else {//caso 5 file
        for ($i = 0; $i < count($images); $i++) {
            echo "a[$i]='" . $folder . "/" . $images[$i]['img'] . "';\n";
            if (strrpos($images[$i]['href'], 'http') !== false)
                echo "link[$i]='" . $images[$i]['href'] . "';\n";
            else
                echo "link[$i]='http://" . $images[$i]['href'] . "';\n";
        }
    }
?>

        //thumbs style
        var styleForThumbs ="" ;
        var dispalyThumbs= true;
        if(styleForThumb=='black'){
        
        styleForThumbs = 'thumbBlackStyle';
        }
        else{
            if(styleForThumb=='white'){
                styleForThumbs = 'thumbWhiteStyle';
            }
            else
                styleForThumbs = "";

        }
        
        //dim per il div della thumb
        if (setShowThumbs.indexOf('no')!=-1) {
            dispalyThumbs = false;
        }
//        document.getElementById('custom_thumb').style.display = 'none';
//        jQuery('#custom_thumb').css('display','none');
        
//    }else{
//        document.getElementById('custom_thumb').style.display = 'block';
//
//        document.getElementById('custom_thumb').style.width = widthDivsThumbs+'px';
//        document.getElementById('custom_thumb').style.height = heigthDivsThumbs+'px';
//
//    }
//         if(animation == 'slide'){
//             document.getElementById('custom_thumb').onmouseover = "javascript:addAnimation(this.id)";
//
//         }
        
        
        var selector = <?php echo '"#' . $divToCustomize . '"'; ?>; // CSS Selector/s for element/s you want to apply fade effect to.
        var hoverOverSpeed = "500"; // Hover over fade speed (in milliseconds)
        var hoverOutSpeed = "300"; // Hover out fade speed (in milliseconds)
        var indiceAccesso=0;
        // Start JQuery

        jQuery(document).ready(function() {  


            (function($){
                jQuery.fn.backOpacity = function(settings){
                    // Default and argument settings
                    settings = jQuery.extend({background: '#000000', opacity: 0.5}, settings);

                    // Loop through each element given and add an opacity element
                    jQuery(this).each(function(intIndex){
                        // For fixing background element's positions/sizes these variables are needed
                        var pt = parseInt($(this).css('paddingTop'));
                        var pb = parseInt($(this).css('paddingBottom'));
                        var pl = parseInt($(this).css('paddingLeft'));
                        var pr = parseInt($(this).css('paddingRight'));
                        var fixedleft = parseInt($(this).css('marginLeft'));
                        var fixedright = parseInt($(this).css('marginRight'));

                        // Element offset width
                        var parentow = $(this).width();

                        // Fixed variables
                        var fixedwidth, fixedheight, fixedleft, fixedright = 0;

                        // Calculate fixing positions/sizes
                        fixedwidth = parentow + pl + pr;
                        fixedheight = $(this).height() + pt + pb;

                        // Add background element
                        $(document.createElement('div')).
                            addClass('classBackRotator').
                            width(fixedwidth).
                            height(fixedheight).
                            css({backgroundColor:settings.background, opacity:settings.opacity, position:'relative', marginLeft:fixedleft+'px', marginRight:fixedright+'px', left:0, top:0, bottom:0, zIndex:((10)+intIndex*10)}).
                            insertAfter($(this));
                        
                        // Set positions for the content element
                        $(this).css({width: parentow, position:'absolute', zIndex:((20)+intIndex*20)});
                    });

                    // Return
                    return jQuery;
                };
            })(jQuery);

            // Animate Fade Effects
            if(jQuery.browser.safari || jQuery.browser.opera){
                            var url = window.location.href;
                            url= url.substring(0, url.indexOf('/', 7));
                            if(window.location.href.indexOf('localhost')>=0)
                            url+='/joomla_prog_cosacucini/';
            }
                
	
            jQuery(selector).css({background:'none'}); //removes default CSS :hover effect

            jQuery(selector).backOpacity({background: '#ccc', opacity: '1'}); // Initiate default background opacity

            if(jQuery.browser.safari || jQuery.browser.opera){
                            jQuery(selector).siblings('div').stop().css("background-image", "url('"+url+"/"+a[0]+"')"); //fade out on hover

                        }
                        else

                        jQuery(selector).siblings('div').stop().css("background-image", "url('"+window.location+"/"+a[0]+"')"); //fade out on hover

            
            jQuery(selector).bind('ruota',
		
            function() {
                setTimeout(function(){ 
                    jQuery(selector).siblings('div').stop().animate({'opacity':0},hoverOverSpeed , function (){
                        if(jQuery.browser.safari || jQuery.browser.opera){
                            jQuery(selector).siblings('div').stop().css("background-image", "url('"+url+"/"+a[indiceAccesso%a.length]+"')"); //fade out on hover

                        }
                        else

                        jQuery(selector).siblings('div').stop().css("background-image", "url('"+window.location+"/"+a[indiceAccesso%a.length]+"')"); //fade out on hover

                        setTimeout(function(){ 

                            jQuery(selector).siblings('div').stop().animate({'opacity':1}, hoverOutSpeed); 
                        }, 1000);

                                                
                    }); 
                }, 1500);
			
                  
                 
                //                }).trigger('click');
            });
            jQuery(selector).trigger('ruota');
            indiceAccesso++;
            window.setInterval(function(){
                jQuery(selector).trigger('ruota');
                
                 jQuery(selector).click(function(){
                window.location = link[indiceAccesso%(a.length)];
            });
                indiceAccesso++;
            }, <?php echo $time; ?>);

            if(dispalyThumbs){
                for(i=0; i<a.length ; i++){
                    if(jQuery.browser.safari || jQuery.browser.opera){
                        jQuery('#custom_thumb').append('<a class="modal" href="'+url+'/'+a[i]+'">'+
                            '<img class="'+styleForThumbs+'" src="'+window.location.href+'/'+a[i]+'" '+
                            ' onmouseover="javascript:addAnimation(); " onmouseout="javascript: removeEffect();return false;"'+
                            'style="width: '+<?php echo $widthForThumbs; ?>+'px; height: '
                        +<?php echo $heigthForThumbs; ?>+'px; " />');
                    }
                    else{
                        jQuery('#custom_thumb').append('<a class="modal" href="'+window.location+'/'+a[i]+'">'
                            +'<img class="'+styleForThumbs+'" src="'+window.location+'/'+a[i]+'" '
                            +'onmouseover="javascript:addAnimation(); " onmouseout="javascript: removeEffect();return false;"'
                        +'style="width: '+<?php echo $widthForThumbs; ?>+'px; height: '+<?php echo $heigthForThumbs; ?>+'px; " />');
                    }

                }//for
            }


        });//end/
function addAnimation(id){

    switch("<?php echo $animation; ?>"){
        case 'slide':
//jQuery('#effect').show("slow");
jQuery('#effect').css('visibility','visible');
//            jQuery('#custom_thumb').slideUp( 'slow',function(){
//                jQuery('#custom_thumb').slideDown( 'slow');
//            });
            break;
        case 'fade':
                        alert('fade');

            break;
    }
}

function removeEffect(){
    jQuery('#effect').hide('slow');
} 

</script>
<style>
    .thumbBlackStyle{
        -moz-box-shadow: 10px 10px 11px #000000;
        -webkit-box-shadow: 10px 10px 11px #000000;
        box-shadow: 10px 10px 11px #000000;
        margin: 10px;
    }
    .thumbWhiteStyle{
        -moz-box-shadow: 10px 10px 11px #ffffff;
        -webkit-box-shadow: 10px 10px 11px #ffffff;
        box-shadow: 10px 10px 11px #ffffff;
        margin: 10px;
    }
    
    #custom_thumb{
        display: block;
        width : <?php echo $widthDivsThumbs; ?> ;
        height : <?php echo $heigthDivsThumbs; ?> ;
        position: relative;
        
    }
    #effect{
        position: relative;
        top: -50px;

visibility: hidden;
        height : 50px ;
        background-color: #0000FF;
        
    }
    
</style>

<div  id="custom_thumb"   ></div>

    <div id="effect"  >dsjhklfaghsd</div>